package com.example.petshop.controller;

import com.example.petshop.entity.Goods;
import com.example.petshop.entity.Shop;
import com.example.petshop.service.GoodsService;
import com.example.petshop.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    private ShopService shopService;

    @Autowired
    private GoodsService goodsService;

    @GetMapping("/details/{shopId}")
    public Shop getShopDetails(@PathVariable Integer shopId) {

        return shopService.getShopById(shopId);
    }

    @GetMapping("/{shopId}/goods")
    public List<Goods> getGoodsByShop(@PathVariable Integer shopId) {

        return goodsService.getGoodsByShopId(shopId);
    }
    @GetMapping("/all")
    public List<Shop> getAllShops() {
        return shopService.getAllShops();
    }
    @PostMapping("/create")
    public ResponseEntity<Void> createShop(@RequestBody Shop shop) {
        // 调用服务层的方法来创建新的商店
        shopService.createShop(shop);
        return ResponseEntity.ok().build();
    }
    @DeleteMapping("/delete/{shopId}")
    public ResponseEntity<Void> deleteShop(@PathVariable Integer shopId) {
        // 调用服务层的方法来删除商店
        shopService.deleteShop(shopId);
        return ResponseEntity.ok().build();
    }

    @PutMapping("/update")
    public ResponseEntity<Void> updateShop(@RequestBody Shop shop) {
        // 调用服务层的方法来更新商店
        shopService.updateShop(shop);
        return ResponseEntity.ok().build();
    }
}
